<extend name="Public:common"/>
<block name="main">
    <div data-am-widget="tabs" class="am-tabs am-tabs-secondary" >
        <ul class="am-tabs-nav am-cf">
            <if condition="$type eq 1">
                <li class=""><a href="[data-tab-panel-2]">支出</a></li>
                <li class="am-active"><a href="[data-tab-panel-1]">收入</a></li>
            <else/>
                <li class="am-active"><a href="[data-tab-panel-2]">支出</a></li>
                <li class=""><a href="[data-tab-panel-1]">收入</a></li>
            </if>
        </ul>
        <div class="am-tabs-bd">
            <if condition="$type eq 1">
                <div data-tab-panel-2 class="am-tab-panel">
            <else/>
                <div data-tab-panel-2 class="am-tab-panel am-active">
            </if>
                <form class="am-form am-form-horizontal" enctype="multipart/form-data" method="post" data-am-validator="H5validation:false">
                    <legend>添加支出</legend>
                    <input type="hidden" name="add_type" value="2">
                    <div class="am-input-group">
                        <span class="am-input-group-label"><b>金额</b></span>
                        <input type="number" class="am-form-field" id="text-money" name="add_money" step=0.01 placeholder="输入支出金额">
                        <p></p>
                    </div>
                    <div><p></p></div>
                    <div class="am-input-group">
                        <span class="am-input-group-label"><b>账户</b></span>
                        <select id="select-funds" class="am-form-field" name="add_funds">
                        <foreach name="FundsData" item="data">
                            <option value="{$data.id}">{$data.name}</option>
                        </foreach>
                        </select>
                        <span class="am-form-caret"></span>
                    </div>
                    <div><p></p></div>
                    <div class="am-input-group">
                        <span class="am-input-group-label"><b>分类</b></span>
                        <select id="select-class" class="am-form-field" name="add_class">
                        <foreach name="outMoneyClass" item="ClassName">
                            <option value="{$key}">{$ClassName}</option>
                        </foreach>
                        </select>
                        <span class="am-form-caret"></span>
                    </div>
                    <div><p></p></div>
                    <div class="am-input-group">
                        <span class="am-input-group-label"><b>备注</b></span>
                        <input type="text" class="am-form-field" id="text-mark" name="add_mark" placeholder="输入支出信息">
                        <span class="am-input-group-btn am-form-file">
                            <button type="button" class="am-btn am-btn-default"><i class="am-icon-cloud-upload"></i> 上传图片</button>
                            <input id="doc-form-file-out" type="file" name="add_photo[]" accept=".jpg, .gif, .png, .jpeg" multiple />
                        </span>
                    </div>
                    <div class="file-group-out" style="display: none;"><p></p></div>
                    <div class="am-input-group file-group-out" style="display: none;">
                        <span class="am-input-group-label"><b>附件</b></span>
                        <div id="file-list-out" class="am-form-field" style="height: auto;"></div>
                    </div>
                    <div><p></p></div>
                    <div class="am-input-group">
                        <span class="am-input-group-label"><b>时间</b></span>
                        <input type="date" class="am-form-field" id="text-time" name="add_time" 
                                value="<php>echo date("Y-m-d",time());</php>" />
                    </div>
                    
                    <p><hr data-am-widget="divider" style="" class="am-divider am-divider-dashed" /></p>
                    
                    <p><button type="submit" name="submit" class="am-btn am-btn-warning am-btn-block">添加</button></p>
                    <p><a href="{$refURL}" class="am-btn am-btn-block am-btn-default">返回</a></p>
                </form>
            </div>
            <if condition="$type eq 1">
                <div data-tab-panel-1 class="am-tab-panel am-active">
            <else/>
                <div data-tab-panel-1 class="am-tab-panel ">
            </if>
            
                <form class="am-form am-form-horizontal" enctype="multipart/form-data" method="post" data-am-validator="H5validation:false">
                    <legend>添加收入</legend>
                    <input type="hidden" name="add_type" value="1">
                    <div class="am-input-group">
                        <span class="am-input-group-label"><b>金额</b></span>
                        <input type="number" class="am-form-field" id="text-money" name="add_money" step=0.01 placeholder="输入收入金额">
                        <p></p>
                    </div>
                    <div><p></p></div>
                    <div class="am-input-group">
                        <span class="am-input-group-label"><b>账户</b></span>
                        <select id="select-funds" class="am-form-field" name="add_funds">
                        <foreach name="FundsData" item="data">
                            <option value="{$data.id}">{$data.name}</option>
                        </foreach>
                        </select>
                        <span class="am-form-caret"></span>
                    </div>
                    <div><p></p></div>
                    <div class="am-input-group">
                        <span class="am-input-group-label"><b>分类</b></span>
                        <select id="select-class" class="am-form-field" name="add_class">
                        <foreach name="inMoneyClass" item="ClassName">
                            <option value="{$key}">{$ClassName}</option>
                        </foreach>
                        </select>
                        <span class="am-form-caret"></span>
                    </div>
                    <div><p></p></div>
                    <div class="am-input-group">
                        <span class="am-input-group-label"><b>备注</b></span>
                        <input type="text" class="am-form-field" id="text-mark" name="add_mark" placeholder="输入支出信息">
                        <span class="am-input-group-btn am-form-file">
                            <button type="button" class="am-btn am-btn-default"><i class="am-icon-cloud-upload"></i> 上传图片</button>
                            <input id="doc-form-file-in" type="file" name="add_photo[]" accept=".jpg, .gif, .png, .jpeg" multiple />
                        </span>
                    </div>
                    <div class="file-group-in" style="display: none;"><p></p></div>
                    <div class="am-input-group file-group-in" style="display: none;">
                        <span class="am-input-group-label"><b>附件</b></span>
                        <div id="file-list-in" class="am-form-field" style="height: auto;"></div>
                    </div>
                    <div><p></p></div>
                    <div class="am-input-group">
                        <span class="am-input-group-label"><b>时间</b></span>
                        <input type="date" class="am-form-field" id="text-time" name="add_time" 
                                value="<php>echo date("Y-m-d",time());</php>" />
                    </div>
                    <p><hr data-am-widget="divider" style="" class="am-divider am-divider-dashed" /></p>
                    
                    <p><button type="submit" name="submit" class="am-btn am-btn-success am-btn-block">添加</button></p>
                    <p><a href="{$refURL}" class="am-btn am-btn-block am-btn-default">返回</a></p>
                </form>
            </div>
        </div>
    </div>
    <include file="Public:list_common"/>
    <gt name="PageMax" value="1">
        <a href="__APP__/Home/Index/index/p/2" class="am-btn am-btn-block am-btn-default">更多</a>
    </gt>
</block>

<block name="javascript">
    <script>
      function ResetFormFile() {
          $('.file-group-out').hide();
          $('.file-group-in').hide();
          $('#doc-form-file-out').val('');
          $('#doc-form-file-in').val('');
      }

      $(function() {
        $('#doc-form-file-out').on('change', function() {
          var fileNames = '';
          var fileSize = 0;
          if (this.files.length > 9) {
            alert("上传文件数量不能超过9个。");
            ResetFormFile();
            return;
          }
          $.each(this.files, function() {
            fileNames += '<span class="am-badge">' + this.name + '</span> ';
            fileSize += this.size;
          });
          if (fileSize > 3*1024*1024) {
            alert("单次上传文件体积不能超过3MB。");
            ResetFormFile();
            return;
          }
          $('#file-list-out').html(fileNames);
          if (fileNames == '') {
            $('.file-group-out').hide();
          } else {
            $('.file-group-out').show();
          }
        });

        $('#doc-form-file-in').on('change', function() {
          var fileNames = '';
          var fileSize = 0;
          if (this.files.length > 9) {
            alert("上传文件数量不能超过9个。");
            ResetFormFile();
            return;
          }
          $.each(this.files, function() {
            fileNames += '<span class="am-badge">' + this.name + '</span> ';
            fileSize += this.size;
          });
          if (fileSize > 3*1024*1024) {
            alert("单次上传文件体积不能超过3MB。");
            ResetFormFile();
            return;
          }
          $('#file-list-in').html(fileNames);
          if (fileNames == '') {
            $('.file-group-in').hide();
          } else {
            $('.file-group-in').show();
          }
        });
      });
    </script>
</block>